package com.margo.project.web.mvcconfig.deserialize;

import java.io.IOException;

import org.springframework.util.StringUtils;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

/**
 * json序列化
 * @author fxb208
 *
 */
public class MargoStringJsonDeserializer extends JsonDeserializer<String>{

	@Override
	public String deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
		try {
            if (jsonParser != null && !StringUtils.isEmpty(jsonParser.getText())) {
            	String[] arrStr=jsonParser.getText().split(";");
        		StringBuilder sb=new StringBuilder();
        		sb.append("'");
        		for(int i=0;i<arrStr.length;i++) {
        			sb.append(arrStr[i]).append("'");
        			if(i<arrStr.length-1) {
        				sb.append(",");
        			}
        		}
        		return sb.toString();
            } else {
                return null;
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
            throw new RuntimeException(e);
        }
	}

}
